package com.zjh.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zjh.admin.entity.DO.SysMenu;
import com.zjh.admin.service.ISysMenuService;
import com.zjh.common.entity.Response;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-06-22
 */
@RestController
@RequestMapping("/Admin/sys-menu")
public class SysMenuController {

    @Resource
    private ISysMenuService sysMenuService;

    @GetMapping
    public Response<?> getAllMenu() {

        List<SysMenu> list = sysMenuService.list();

        return Response.success(list);
    }

    @PostMapping("saveOrUpdate")
    public Response<?> saveOrUpdate(@RequestBody SysMenu sysMenu) {
        QueryWrapper<SysMenu> queryWrapper = new QueryWrapper<>();

        if (sysMenu.getId() == null) {
            sysMenuService.save(sysMenu);
        } else {
            queryWrapper.eq("id", sysMenu.getId());
            sysMenuService.update(sysMenu, queryWrapper);
        }

        return Response.success();
    }

}

